package controllers;

import helpers.ConsoleUtils;

import java.io.File;
import java.util.ArrayList;

import be.objectify.deadbolt.java.actions.Group;
import be.objectify.deadbolt.java.actions.Restrict;

import models.Company;
import models.Report;
import play.mvc.Result;
import services.ReportService;
import views.html.reports.list;

public class Reports extends play.mvc.Controller {
	
	// private static final SynchronizationService synchService = SynchronizationService.getService();
	private static final ReportService reportService = ReportService.getService();
	
	@Restrict(@Group(Application.ROLE_USER))
	public static Result listReports() {
		// final Company company = ConsoleUtils.getCompany();
		// List<Report> reports = synchService.synchronizeReports(company);
		// Collections.sort(reports, new Comparator<Report>() {
		// @Override
		// public int compare(Report r1, Report r2) {
		// return r2.getGeneratedTime().compareTo(r1.getGeneratedTime());
		// }
		// });
		// return ok(list.render(reports));
		return ok(list.render(new ArrayList<Report>()));
	}
	
	@Restrict(@Group(Application.ROLE_USER))
	public static Result showReport(String projectName, long reportId) {
		final Company company = ConsoleUtils.getCompany();
		return ok(new File(reportService.getReportHtmlPath(reportService.getProjectReportsDirectory(company, projectName), reportId)));
	}
	
}
